# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=pygame
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=2.1.3.dev8
pkgrel=2
pkgdesc='A Python library for making multimedia applications like games (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('spdx:LGPL-2.1')
url='https://www.pygame.org'
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libmodplug"
         "${MINGW_PACKAGE_PREFIX}-libogg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-mpg123"
         "${MINGW_PACKAGE_PREFIX}-opus"
         "${MINGW_PACKAGE_PREFIX}-opusfile"
         "${MINGW_PACKAGE_PREFIX}-portmidi"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-SDL2_image"
         "${MINGW_PACKAGE_PREFIX}-SDL2_mixer"
         "${MINGW_PACKAGE_PREFIX}-SDL2_ttf"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=('strip')
source=(https://github.com/pygame/pygame/archive/refs/tags/${pkgver}.tar.gz
        001-setup-fixes.patch
        002-camera-extension-fixes.patch)
sha256sums=('1d8a55b5a769eb9521b9d346688d4a060dca3e4497300efc78fb4021bc370199'
            'bbc384971b97e86b8f5a383d48da31b787f5029da0171b7dc2f85c34f4b8d44b'
            'd5269af882bb4b61ff8ca73363b0ed925df3c16347754b49277a9b9af961992c')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/001-setup-fixes.patch
  patch -p1 -i ${srcdir}/002-camera-extension-fixes.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 docs/LGPL.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
